package org.grayrabbit.cloud.core.module;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.grayrabbit.cloud.core.Context;
import org.springframework.context.ApplicationContext;


public class SpringContextUtil implements Context<String, ApplicationContext>{
	private static SpringContextUtil springContextUtil;
	public static Context<String, ApplicationContext> newInstance(){
		synchronized (SpringContextUtil.class) {
			if(springContextUtil==null){
				springContextUtil = new SpringContextUtil();
			}
		}
		return springContextUtil;
	}
	public static final String WEB_APPLICATION_KEY = "web";
	private Map<String,ApplicationContext> context = new ConcurrentHashMap<String, ApplicationContext>();
	@Override
	public Set<String> getKeys() {
		return context.keySet();
	}

	@Override
	public ApplicationContext getValue(String key) {
		return context.get(key);
	}

	@Override
	
	public synchronized void setValue(String key, ApplicationContext value) {
		context.put(key, value);
	}
	
}
